package com.falcon.mojo.v1;

import com.falcon.mojo.AbsMojo;
import com.falcon.util.PathUtil;
import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;

import java.io.File;
import java.io.IOException;

/** 恢复pom */
@Mojo(name = "pom-restore", defaultPhase = LifecyclePhase.INSTALL)
public class PomRestoreMojo extends AbsMojo {

    public void execute() throws MojoExecutionException, MojoFailureException {
        // 恢复 pom
        String backupFile = PathUtil.getBackPomPath(this.project);
        String pomFile = PathUtil.getPomPath(this.project);
        try {
            FileUtils.copyFile(new File(backupFile), new File(pomFile));
        } catch (IOException e) {
            throw new RuntimeException("备份 pom 失败", e);
        }
        getLog().info("pom 恢复成功，恢复文件:" + pomFile);
    }

}
